package com.Home;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@SpringBootApplication
//@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})

@Controller
@ServletComponentScan
@ComponentScan(basePackages={"com.Home"})
public class HomeMain {

    @RequestMapping("/")
    public String greeting(){
        return "index.html";
    }
//    @RequestMapping("/heihei")
//    public String greets(){
//        return "/resources/templates/heihei.html";
//    }
    @RequestMapping("/parms/user")
    public String greetings(String name){
        System.out.println(name);
        return "mimimimimimi";
    }

    @Bean
    public EmbeddedServletContainerCustomizer containerCustomizer() {
        return new EmbeddedServletContainerCustomizer(){
            @Override
            public void customize(ConfigurableEmbeddedServletContainer container) {
                container.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/404.html"));
                container.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/404.html"));
                container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/404.html"));
            }
        };
    }

    public static void main(String[] args) throws Exception{
        try{
            SpringApplication.run(HomeMain.class, args);
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
